package top.zywork.strategy.order;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import top.zywork.dto.OrderPayDTO;
import top.zywork.dto.RefundOrderDTO;
import top.zywork.enums.PayOrderEnum;
import top.zywork.enums.RefundOrderEnum;
import top.zywork.utils.SpringUtils;
import top.zywork.weixin.PayResult;
import top.zywork.weixin.RefundResult;

/**
 * @author Animo
 * @Date 2020/10/21
 * @Blog http://www.ljyanimo.com
 */
@Component
public class OrderContext {

    private OrderService payNewInstance(String name){
        PayOrderEnum anEnum = PayOrderEnum.getEnum(name);
        return (OrderService) SpringUtils.getBean(anEnum.getClazz());
    }

    private OrderService refundNewInstance(String name){
        RefundOrderEnum anEnum = RefundOrderEnum.getEnum(name);
        return (OrderService) SpringUtils.getBean(anEnum.getClazz());
    }

    public OrderPayDTO OrderValidation( String name,String orderId){
        return payNewInstance(name).orderValidation(orderId);
    }

    public RefundOrderDTO refundValidation(String name,String orderId){
        return refundNewInstance(name).refundValidation(orderId);
    }

    public void wxPaySuccessNotify(String name, PayResult payResult){
        payNewInstance(name).wxPaySuccessNotify(payResult);
    }

    public void wxPayFailNotify(String name, PayResult payResult){
        payNewInstance(name).wxPaySuccessNotify(payResult);
    }

    public void wxRefundSuccessNotify(String name,RefundResult refundResult){
        refundNewInstance(name).wxRefundSuccessNotify(refundResult);
    }

    public void wxRefundFailNotify(String name,RefundResult refundResult){
        refundNewInstance(name).wxRefundFailNotify(refundResult);
    }

}
